<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

</head>

<body>
    <!-- <script src="../big-event/libs/jquery/jquery.min.js"></script> -->
    <form>
        <div>
            <label for="姓名"></label>
            <input type="text" name="username">
        </div>
        <div>
            <label for="密码"></label>
            <input type="text" name="password">
        </div>
        <button type="button">发布</button>

    </form>

    <script>
        const usernameInput = document.querySelector("[name = 'username']")
        const passwordInput = document.querySelector("[name = 'password']")
        // console.log(usernameInput)
        const button = document.querySelector('button')
        button.onclick = function () {
            const fd = new FormData()
            const username = usernameInput.value
            const password = passwordInput.value
            fd.append("username", username)
            fd.append("password", password)
            console.log(fd)
            fd.forEach((value, key) => console.log(value, key))


            // // 优化 简洁代码
            // const form = document.querySelector('form')
            // // 注意事项：这个form标签中的表单组件必须要有 name属性
            // const fd = new FormData(form)
            // fd.forEach((value, key) => console.log(value, key))
        }
    </script>

</body>

</html>